<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="telephone=no" name="format-detection" />
    <title>申请推广</title>
    <link href="{{asset('/mobile/css/main.css')}}" rel="stylesheet" type="text/css">
    <link href="{{asset('/mobile/css/style.css')}}" rel="stylesheet" type="text/css">
    <link href="{{asset('/mobile/css/shake.css')}}" rel="stylesheet" type="text/css">
    <link href="{{asset('/mobile/css/font-awesome.min.css')}}" rel="stylesheet" type="text/css">
    <link href="{{asset('/mobile/css/animate.min.css')}}" rel="stylesheet" type="text/css">
    <link href="{{asset('/mobile/css/idangerous.swiper.css')}}" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="{{asset('/mobile/js/jquery-1.8.3.min.js')}}"></script>
    <script type="text/javascript" src="{{asset('/mobile/js/wo.js')}}"></script>
</head>
<body style="background-color: #fff !important;">
<div class="warpe">
    <div class="head">
        申请二级推广
    </div>
    <div class="main">
        <div class="regall">
            <form class="btn-form" action="/mobile/apply" method="POST">
                {{csrf_field()}}
                <div class="reginput">
                    <input type="text" disabled placeholder="上级推广：{{$agent->realname}}" style="border-top: .1rem #ededed solid;">
                    <input type="text" value="{{old('realname')}}" name="realname" placeholder="真实姓名" style="border-top: .1rem #ededed solid;">
                    <input type="text" value="{{old('address')}}" name="address" placeholder="推广区域" style="border-top: .1rem #ededed solid;">
                    <input type="text" value="{{old('mobile')}}" name="mobile" placeholder="手机号" style="border-top: .1rem #ededed solid;">
                    <input type="text" value="{{old('code')}}" name="code" placeholder="验证码" style="border-top: .1rem #ededed solid;">
                    <div class="yzmdiv">
                        <a class="btn-code" href="javascript:void(0)" style="background-color: #ff8400;color: #fff;font-size:13px">获取验证码</a>
                    </div>
                    <input type="hidden" name="open_id" value="{{$origin_info['openid']}}">
                    <input type="hidden" name="unionid" value="{{$origin_info['unionid']}}">
                    <input type="hidden" name="nickname" value="{{$origin_info['nickname']}}">
                    <input type="hidden" name="avatar" value="{{$origin_info['headimgurl']}}">
                    <input type="hidden" name="pid" value="{{$agent->id}}">
                </div>
                <div class="regTxt">
                    <p><label><input class="agreement" type="checkbox"><a href="/mobile/agreement">同意"乐游推广注册与服务协议"</a></label></p>
                </div>
                <div class="id_bth inersest_bth animated bounceIn">
                    <a class="btn-submit" href="javascript:void(0)">提交申请</a>
                </div>
            </form>
            <div style="text-align:center;font-weight:bold;font-size:13px">
                <span id="err_msg" style="color:red;">
                    @if ($errors->any())          
                      {{ $errors->first() }}
                    @endif
                </span>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var clock = '',
        nums =60,
        tn;

    $(".btn-code").click(function(){
        var mobile = $("input[name=mobile]").val();
        if (!mobile) {
            $('#err_msg').text("手机号不能为空");
            return false;
        }
        $.ajax({
            type: "get",
            dataType: "json",
            url: '/mobile/get_code',
            data: {
                mobile: mobile
            },
            success: function (data) {
                if (data.flag) {
                    sendCode();
                } else {
                    $('#err_msg').text(data.message);
                }
            }
        }); 
    });

    function sendCode()
    {
        btn = $('.btn-code');
        btn.unbind('click');
        $(btn).css({"background-color":"#ccc"});
        $(btn).text(nums+'秒重新获取')
        clock = setInterval(doLoop, 1000); //一秒执行一次
    }

    function doLoop(){
        nums--;
        if(nums > 0){
            $(btn).text(nums+'秒重新获取')
        }else{
            clearInterval(clock); //清除js定时器
            btn.disabled = false;
            $(btn).text('获取验证码');
                //btn.value = '点击发送验证码';
            $(btn).css({"background-color":"#ff8400"});
            nums = 60; //重置时间
            $(".btn-code").click(function(){
                sendCode();
            });
        }
    }

    $(".btn-submit").click(function(){
        if ($('.agreement').is(':checked')) {
            var realname = $("input[name=realname]").val();
            var address = $("input[name=address]").val();
            var mobile = $("input[name=mobile]").val();
            var code = $("input[name=code]").val();
            var open_id = $("input[name=open_id]").val();
            var unionid = $("input[name=unionid]").val();
            var nickname = $("input[name=nickname]").val();
            var avatar = $("input[name=avatar]").val();
            var pid = $("input[name=pid]").val();
            $.ajax({
                type: "POST",
                dataType: "json",
                url: '/mobile/apply',
                data: {
                    realname: realname,
                    address: address,
                    mobile: mobile,
                    code: code,
                    open_id: open_id,
                    unionid: unionid,
                    nickname: nickname,
                    avatar: avatar,
                    pid: pid,
                    _token: "{{ csrf_token() }}"
                },
                success: function (data) {
                    if (data.flag) {
                        window.location.href = "/mobile/index";
                    } else {
                        $("#err_msg").text(data.msg);
                    }
                }
            }); 
        } else {
            $("#err_msg").text('请勾选推广注册与服务协议');
        }
    });
</script>
</body>
</html>